<template>
    <view>
      <view v-if="poptype == 'tips'" class="popup-wrap">
        <view class="title">正确测量方法</view>
        <view class="content">
          <view class="contentWrap" v-if="healthType == 'bmi'">
            <view class="contentItem"
              >1.将体脂称放置在坚固且平坦的地面上，测量过程请勿弯曲膝关节。</view
            >
            <img
              class="img"
              mode="widthFix"
              src="https://ainengli.meilianshuke.com/jkhx/BMI2.png"
              alt=""
            />
            <view class="contentItem">赤脚站立，并将脚心对准体脂称中间。</view>
            <img
              class="img"
              mode="widthFix"
              src="https://ainengli.meilianshuke.com/jkhx/BMI1.png"
            />
          </view>
          <view class="contentWrap" v-if="healthType == 'sbp'">
            <view class="contentItem">1.测量前30分钟不得进行剧烈运动。</view>
            <view class="contentItem">2.测量的时候，手臂要放松，放置在与心脏齐平的桌面上。</view>
            <img
              class="img"
              mode="widthFix"
              src="https://ainengli.meilianshuke.com/jkhx/bloodPressure.png"
            />
          </view>
          <view class="contentWrap" v-if="healthType == 'blood_sugar'">
            <view class="contentItem">1.沿着箭头方向将试纸插入血糖仪。</view>
            <img
              class="img"
              mode="widthFix"
              src="https://ainengli.meilianshuke.com/jkhx/bloodSugar1.png"
            />
            <view class="contentItem">2.将血滴接触试纸窗口的前沿位置。</view>
            <img
              class="img"
              mode="widthFix"
              src="https://ainengli.meilianshuke.com/jkhx/bloodSugar2.png"
            />
          </view>
          <view class="fixedBtn" @tap="goit">
            <view class="name">知道了</view>
          </view>
        </view>
      </view>
      <view v-else-if="poptype != 'tips' && healthType == 'sleep'" class="popup-wrap">
        <view class="title"> 睡眠录入 </view>

        <view class="measureTime sleepTime" style="margin-top: 32rpx">
          <text class="name">入睡时间</text>
          <view class="time" @tap="timeSleepFun(state.sleepDate, 'sleep')">
            <text class="titles">{{ parseTime(state.sleepDate, '{m}月{d}日 {h}:{i}') }}</text>
            <img
              class="img"
              src="https://ainengli.meilianshuke.com/jkhx/common/my-arrow-right.png"
              alt=""
            />
          </view>
        </view>
        <view class="measureTime sleepTime">
          <text class="name">醒来时间</text>
          <view class="time" @tap="timeSleepFun(state.wakeupDate, 'wakeup')">
            <text class="titles">{{ parseTime(state.wakeupDate, '{m}月{d}日 {h}:{i}') }}</text>
            <img
              class="img"
              src="https://ainengli.meilianshuke.com/jkhx/common/my-arrow-right.png"
              alt=""
            />
          </view>
        </view>
        <view class="measureTime sleepTime">
          <text class="name">睡眠日期</text>
          <view class="time">
            <text class="titles">{{ parseTime(state.wakeupDate, '{m}月{d}日') }}</text>
          </view>
        </view>
        <view class="fixedBtn" @tap="sureSleep">
          <text class="name">提交</text>
        </view>
      </view>
      <view v-else-if="poptype != 'tips' && healthType != 'sleep' && isShow" class="popup-wrap">
        <view class="title">
          {{ state.editType == 'edit' ? '修改' : getCheckRulesTypeName(healthType) }}
        </view>
        <view class="tabKey">
          <text
            :class="[
              'name',
              healthType == 'whr' ||
              healthType == 'heart_rate' ||
              healthType == 'spo2' ||
              healthType == 'sleep' ||
              healthType == 'water' ||
              healthType == 'blood_ketone' ||
              healthType == 'uric_acid' ||
              healthType == 'blood_fat' ||
              healthType == 'liver_function'
                ? 'on'
                : ''
            ]"
            @tap="measurementFun"
            >{{
              healthType == 'bmi'
                ? '如何测量BMI？'
                : healthType == 'whr'
                ? '如何测量腰臀比？'
                : healthType == 'sbp'
                ? '如何测量血压？'
                : healthType == 'blood_sugar'
                ? '如何测量血糖？'
                : '如何测量？'
            }}
          </text>
          <view v-if="state.tabkeyboardShow">
            <view class="keyboard" @tap="measuremenKey('keyboard')">
              <text type="" class="iconfont icon-jianpan1 img" />
              <text class="key">切换键盘</text>
            </view>
          </view>
          <view v-else>
            <view class="keyboard" @tap="measuremenKey('slideRule')">
              <text type="" class="iconfont icon-huachi1 img" />
              <text class="key">切换滑尺</text>
            </view>
          </view>
        </view>
        <view class="listWraps" v-if="healthType == 'blood_sugar'">
          <scroll-view class="scroll-view_H" scroll-x="true" :scroll-left="scrollLeft">
            <view
              :class="['item', state.bloodSugarActive == index ? 'on' : '']"
              v-for="(item, index) in bloodSugarList"
              :key="index"
              @tap="bloodSugarTab(item, index)"
            >
              <text class="name">{{ item.name }}</text>
              <text class="time-title">{{ item.title }}</text>
            </view>
          </scroll-view>
        </view>
        <view class="scoring" v-if="state.slideRuleShow">
          <scroll-view
            scroll-y="true"
            class="scroll-slide"
          >
            <slideRule
              v-for="(item, index) of slideInfoList"
              :key="index"
              style="margin-bottom: 40rpx"
              :message="item"
              :init="item.init"
              @childEvent="childEvent"
            />
          </scroll-view>
        </view>
        <view class="measure" v-else>
          <view class="numWrap cf">
            <view class="item" v-for="(item, index) of slideInfoList" :key="index">
              <input
                v-model="item.value"
                class="value"
                type="digit"
                placeholder="--"
                :maxlength="5"
              />
              <view class="wraps">
                <text class="name">{{ item.name }}</text>
                <text class="name">{{ item.unit }}</text>
              </view>
            </view>
          </view>
        </view>
        <view class="measureTime">
          <text class="name" v-if="healthType != 'water'">测量时间</text>
          <text class="name" v-else>录入日期</text>
          <view class="time" @tap="timeFun">
            <text class="titles">{{
              healthType == 'water'
                ? parseTime(state.time, '{y}年{m}月{d}日')
                : parseTime(state.time, '{m}月{d}日 {h}:{i}')
            }}</text>
            <img
              class="img"
              src="https://ainengli.meilianshuke.com/jkhx/common/my-arrow-right.png"
              alt=""
            />
          </view>
        </view>
        <view v-if="healthType == 'bmi' && isSign" class="upload-title">
          <text>人体成分检测报告</text>
          <text class="tips">（请拍照上传，最多可上传9张图片）</text>
        </view>
        <!-- 图片上传 -->
        <view v-if="healthType == 'bmi' && isSign" class="file-box">
          <scroll-view
            scroll-y="true"
            class="scroll-upload"
          >        
            <up-upload
              :fileList="picInfo && picInfo.campWieghtPics ? picInfo.campWieghtPics : []"
              @afterRead="selectFile"
              @delete="deleteFile"
              name="3"
              multiple
              :maxCount="9"
              :previewFullImage="true"
              :maxSize="10485760"
              @oversize="handleOversize"
            />
          </scroll-view>
        </view>
        <view class="fixedBtn" @tap="sure">
          <text class="name">提交</text>
        </view>
      </view>
    </view>
</template>

<script setup lang="ts">
import { debounce, parseTime } from '@/utils/tools'
import { ref, reactive, nextTick, watch } from 'vue'
import slideRule from './slideRule'

const props = defineProps({
    poptype: {
      type: String,
      default: ''
    },
    healthType: {
      type: String,
      default: ''
    },
    list: {
      type: Object,
      default: () => []
    },
    slideInfoList: {
      type: Object,
      default: () => []
    },
    picInfo: {
      type: Object,
      default: () => {}
    },
    empi: {
      type: String,
      default: ''
    },
    uploading: {
      type: Boolean,
      default: false
    },
    isShow: {
      type: Boolean,
      default: ''
    },
    isSign: {
      type: Boolean,
      default: ''
    },
    isClick: {
      type: Boolean,
      default: ''
    }
})
const emit = defineEmits([
  'onReset',
  'onUpdate',
  'onGoit',
  'onSelectFile',
  'onSave1',
  'onSave2',
  'onSave3',
  'onSave4',
  'timeFun',
  'measurementFun',
  'timeSleepFun',
])
const state = reactive({
  editType: '',
  slideRuleType: '',
  slideRuleShow: true,
  slideRuleTypeDefault: false,
  tabkeyboardShow: true,
  bloodSugarActive: 0,
  minDate: 0,
  time: '',
  datetimeNew: '',
  wakeupDate: '',
  sleepDate: ''
})
// 测量
const bloodSugarList = reactive([
  {
    name: '早起',
    title: '空腹',
    value: 'empty_stomach'
  },
  {
    name: '早餐后',
    title: '2小时',
    value: 'breakfast_after_2'
  },
  {
    name: '午餐前',
    title: '-',
    value: 'lunch_before'
  },
  {
    name: '午餐后',
    title: '2小时',
    value: 'lunch_after_2'
  },
  {
    name: '晚餐前',
    title: '-',
    value: 'dinner_before'
  },
  {
    name: '晚餐后',
    title: '2小时',
    value: 'dinner_after_2'
  },
  {
    name: '睡前',
    title: '-',
    value: 'sleep_before'
  }
])
const updateId = ref('')
let scrollLeft: string = '0rpx'

// 获取录入类型名称
const getCheckRulesTypeName = (type: string) => {
  let name: string = ''
  switch (type) {
    case 'bmi':
      name = '体重录入'
      break
    case 'whr':
      name = '腰臀比录入'
      break
    case 'sbp':
      name = '血压录入'
      break
    case 'heart_rate':
      name = '心率录入'
      break
    case 'blood_sugar':
      name = '血糖录入'
      break
    case 'spo2':
      name = '血氧录入'
      break
    case 'blood_ketone':
      name = '血酮录入'
      break
    case 'uric_acid':
      name = '尿酸录入'
      break
    case 'sleep':
      name = '睡眠录入'
      break
    case 'water':
      name = '饮水录入'
      break
    case 'blood_fat':
      name = '血脂录入'
      break
    case 'liver_function':
      name = '肝功能录入'
      break
    default:
      name = ''
      break
  }
  return name
}

const measuremenKey = (value) => {
  state.tabkeyboardShow = !state.tabkeyboardShow
  state.slideRuleShow = !state.slideRuleShow
  state.slideRuleType = value
  state.slideRuleTypeDefault = true
  if (value == 'slideRule') {
    props.slideInfoList.forEach((val, idx) => {
      val.init = val.value
      val.currentScore = val.value
    })
  } else if (value == 'keyboard') {
    props.slideInfoList.forEach((val, idx) => {
      val.value = val.currentScore
    })
  }
}
const childEvent = (param) => {
  if (
    param &&
    (param.name == '身高' ||
      param.name == '腰围' ||
      param.name == '收缩压' ||
      param.name == '心率' ||
      param.name == '血糖' ||
      param.name == '血氧饱和度' ||
      param.name == '饮水' ||
      param.name == '血酮' ||
      param.name == '尿酸' ||
      param.name == '总胆固醇' ||
      param.name == '谷草转氨酶')
  ) {
    props.slideInfoList[0].value = param.currentSwiper
    props.slideInfoList[0].currentScore = param.currentSwiper
  } else if (
    param &&
    (param.name == '体重' ||
      param.name == '臀围' ||
      param.name == '舒张压' ||
      param.name == '甘油三酯' ||
      param.name == '谷丙转氨酶')
  ) {
    props.slideInfoList[1].value = param.currentSwiper
    props.slideInfoList[1].currentScore = param.currentSwiper
  } else if (
    (param && param.name == '脉搏') ||
    param.name == '高密度脂蛋白' ||
    param.name == 'Y-谷氨酰转肽酶'
  ) {
    props.slideInfoList[2].value = param.currentSwiper
    props.slideInfoList[2].currentScore = param.currentSwiper
  } else if (param && param.name == '低密度脂蛋白') {
    props.slideInfoList[3].value = param.currentSwiper
    props.slideInfoList[3].currentScore = param.currentSwiper
  }
}
const add = (name: string, type: string, editItem: any) => {
  state.tabkeyboardShow = true
  state.slideRuleShow = true
  state.slideRuleType = ''
  state.slideRuleTypeDefault = false
  state.editType = type
  state.time = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}:{s}').replace(/\//g, '-')
  console.log('添加', props.healthType, type, editItem)
  if (type == 'edit') {
    if (
      props.healthType == 'blood_ketone' || 
      props.healthType == 'blood_sugar' || 
      props.healthType == 'uric_acid' || 
      props.healthType == 'liver_function' || 
      props.healthType == 'blood_fat' 
    ) {
      updateId.value = editItem.report.reportId
      if (editItem.report.checkTime) {
        state.time = editItem.report.checkTime
      } else if (editItem.report.realTime) {
        state.time = editItem.report.realTime
      }
    } else {
      updateId.value = editItem.id
      state.time = editItem.collectTime
    }
  }
  state.bloodSugarActive = 0
  if (name == 'sleep') {
    if (type == 'edit') {
      state.sleepDate = parseTime(editItem.paramValue.sleepTime, '{y}-{m}-{d} {h}:{i}')
      state.wakeupDate = parseTime(editItem.paramValue.weekupTime, '{y}-{m}-{d} {h}:{i}')
    } else {
      state.wakeupDate = parseTime(new Date(), '{y}-{m}-{d} 06:00')
      state.sleepDate = getYesterdayAt2200()
    }
  } else if (name == 'blood_sugar') {
    if (type == 'edit') {
      state.bloodSugarActive = 
        bloodSugarList.findIndex((el) => 
        el.name == editItem.details[0].indicatorName 
        || el.title == editItem.details[0].indicatorName)
    } else {
      getBloodSugarTime()
    }
  }
}
const setTime = (val) => {
  state.time = val
}
const setSleepTime = (val) => {
  state.sleepDate = val
}
const setWakeupTime = (val) => {
  state.wakeupDate = val
}
const sure = () => {
  console.log('编辑', updateId.value)
  if (props.isClick == true) {
    return false
  }
  if (state.time == '') {
    uni.showToast({
      title: '请选择测量时间',
      icon: 'none'
    })
    return false
  }
  if (props.uploading) {
    uni.showToast({
      title: '请等待图片上传完成',
      icon: 'none'
    })
    return false
  }
  uni.showLoading({
    title: '加载中'
  })
  let param = {}
  if (props.healthType == 'bmi') {
    const bmiDate = (
      (props.slideInfoList[1].value /
        props.slideInfoList[0].value /
        props.slideInfoList[0].value) *
      10000
    ).toFixed(1)
    if (state.editType == 'edit') {
      param = {
        id: updateId.value,
        empi: props.empi,
        bmi: bmiDate,
        height: props.slideInfoList[0].value,
        weight: props.slideInfoList[1].value,
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      emit('onSave4', param)
    } else {
      param = {
        empi: props.empi,
        bmi: bmiDate,
        height: props.slideInfoList[0].value,
        weight: props.slideInfoList[1].value,
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      emit('onSave1', param)
    }
  } else if (props.healthType == 'whr') {
    const bmiDate = (props.slideInfoList[0].value / props.slideInfoList[1].value).toFixed(2)
    if (state.editType == 'edit') {
      param = {
        id: updateId.value,
        empi: props.empi,
        whr: bmiDate,
        waist: Number(props.slideInfoList[0].value),
        hip: Number(props.slideInfoList[1].value),
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      emit('onSave4', param)
    } else {      
      param = {
        empi: props.empi,
        whr: bmiDate,
        waist: Number(props.slideInfoList[0].value),
        hip: Number(props.slideInfoList[1].value),
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      emit('onSave1', param)
    }
  } else if (props.healthType == 'sbp') {
    if (state.editType == 'edit') {
      param = {
        id: updateId.value,
        empi: props.empi,
        sbp: Number(props.slideInfoList[0].value),
        dbp: Number(props.slideInfoList[1].value),
        pulseRate: Number(props.slideInfoList[2].value),
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      emit('onSave4', param)
    } else {     
      param = {
        empi: props.empi,
        sbp: Number(props.slideInfoList[0].value),
        dbp: Number(props.slideInfoList[1].value),
        pulseRate: Number(props.slideInfoList[2].value),
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      emit('onSave1', param)
    }
  } else if (props.healthType == 'heart_rate') {
    const reg = /^\+?[1-9][0-9]*$/
    if (reg.test(props.slideInfoList[0].value + '')) {
      if (state.editType == 'edit') {
        param = {
          id: updateId.value,
          empi: props.empi,
          heartRate: props.slideInfoList[0].value,
          collectTime: state.time + ':00',
          dataSource: 'MANUAL'
        }
        emit('onSave4', param)
      } else {      
        param = {
          empi: props.empi,
          heartRate: props.slideInfoList[0].value,
          collectTime: state.time + ':00',
          dataSource: 'MANUAL'
        }
        emit('onSave1', param)
      }
    } else {
      uni.hideLoading()
      uni.showToast({
        title: '请输入正整数',
        icon: 'none'
      })
      return false
    }
  } else if (props.healthType == 'blood_sugar') {
    param = {
      report: {
        empi: props.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'blood_sugar'
      },
      details: [
        {
          empi: props.empi,
          indicatorKey: bloodSugarList[state.bloodSugarActive].value,
          indicatorValue: Number(props.slideInfoList[0].value),
          parentKey: 'blood_sugar'
        }
      ]
    }
    if (state.editType == 'edit') {
      param.report['reportId'] = updateId.value
    }
    emit('onSave3', param)
  } else if (props.healthType == 'spo2') {
    if (state.editType == 'edit') {
      param = {
        id: updateId.value,
        empi: props.empi,
        spo2: Math.round(Number(props.slideInfoList[0].value)),
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      emit('onSave4', param)
    } else {
      param = {
        empi: props.empi,
        spo2: Math.round(Number(props.slideInfoList[0].value)),
        collectTime: state.time + ':00',
        dataSource: 'MANUAL'
      }
      emit('onSave1', param)
    }
  } else if (props.healthType == 'water') {
    param = {
      empi: props.empi,
      collectTime: parseTime(state.time, '{y}-{m}-{d} {h}:{i}:{s}'),
      dataSource: 'MANUAL',
      paramKey: 'water',
      paramValue: Math.round(Number(props.slideInfoList[0].value))
    }
    if (state.editType == 'edit') {
      param.id = updateId.value || ''
    }
    emit('onSave2', param)
  } else if (props.healthType == 'blood_ketone') {
    param = {
      report: {
        empi: props.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'blood_ketone'
      },
      details: [
        {
          empi: props.empi,
          indicatorKey: 'blood_ketone_data',
          indicatorValue: Number(props.slideInfoList[0].value),
          parentKey: 'blood_ketone'
        }
      ]
    }
    if (state.editType == 'edit') {
      param.report['reportId'] = updateId.value
    }
    emit('onSave3', param)
  } else if (props.healthType == 'uric_acid') {
    param = {
      report: {
        empi: props.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'uric_acid'
      },
      details: [
        {
          empi: props.empi,
          indicatorKey: 'uric_acid_data',
          indicatorValue: Number(props.slideInfoList[0].value),
          parentKey: 'uric_acid'
        }
      ]
    }
    if (state.editType == 'edit') {
      param.report['reportId'] = updateId.value
    }
    emit('onSave3', param)
  } else if (props.healthType == 'blood_fat') {
    param = {
      report: {
        empi: props.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'blood_fat'
      },
      details: [
        {
          empi: props.empi,
          indicatorKey: 'total_cholesterol',
          indicatorValue: Number(props.slideInfoList[0].value),
          parentKey: 'blood_fat'
        },
        {
          empi: props.empi,
          indicatorKey: 'tg',
          indicatorValue: Number(props.slideInfoList[1].value),
          parentKey: 'blood_fat'
        },

        {
          empi: props.empi,
          indicatorKey: 'hdlc',
          indicatorValue: Number(props.slideInfoList[2].value),
          parentKey: 'blood_fat'
        },
        {
          empi: props.empi,
          indicatorKey: 'ldlc',
          indicatorValue: Number(props.slideInfoList[3].value),
          parentKey: 'blood_fat'
        }
      ]
    }
    if (state.editType == 'edit') {
      param.report['reportId'] = updateId.value
    }
    emit('onSave3', param)
  } else if (props.healthType == 'liver_function') {
    param = {
      report: {
        empi: props.empi,
        reportSource: 'MANUAL',
        checkTime: state.time + ':00',
        indicatorKey: 'liver_function'
      },
      details: [
        {
          empi: props.empi,
          indicatorKey: 'got',
          indicatorValue: Number(props.slideInfoList[0].value),
          parentKey: 'liver_function'
        },
        {
          empi: props.empi,
          indicatorKey: 'gpt',
          indicatorValue: Number(props.slideInfoList[1].value),
          parentKey: 'liver_function'
        },

        {
          empi: props.empi,
          indicatorKey: 'ygt',
          indicatorValue: Number(props.slideInfoList[2].value),
          parentKey: 'liver_function'
        }
      ]
    }
    if (state.editType == 'edit') {
      param.report['reportId'] = updateId.value
    }
    emit('onSave3', param)
  }
  return true
}

const sureSleep = () => {
  uni.showLoading({
    title: '加载中'
  })

  if (new Date(state.wakeupDate).getTime() - new Date(state.sleepDate).getTime() <= 0) {
    uni.hideLoading()
    uni.showToast({
      title: '入睡时间需比醒来时间早',
      icon: 'none'
    })
    return false
  }

  if (
    parseFloat(
      timestampToHours(new Date(state.wakeupDate).getTime() - new Date(state.sleepDate).getTime())
    ) > 16
  ) {
    uni.hideLoading()
    uni.showToast({
      title: '入睡时间和醒来时间间隔过长，请重新选择',
      icon: 'none'
    })
    return false
  }

  console.log(state.sleepDate, state.wakeupDate)

  const data = {
    sleepTime: state.sleepDate + ':00',
    weekupTime: state.wakeupDate + ':00',
    sleepDuration: timestampToHours(
      new Date(state.wakeupDate).getTime() - new Date(state.sleepDate).getTime()
    )
  }
  let param = {
    empi: props.empi,
    collectTime: parseTime(state.wakeupDate, '{y}-{m}-{d} {h}:{i}:{s}'),
    dataSource: 'MANUAL',
    paramKey: 'sleep',
    paramValue: JSON.stringify(data)
  }
  if (state.editType == 'edit') {
    param.id = updateId.value || ''
  }
  emit('onSave2', param)
  return true
}
// 将时间戳转换为小时
const timestampToHours = (timestamp: any) => {
  const differenceInHours = timestamp / (1000 * 60 * 60) // 转换为小时
  return differenceInHours.toFixed(2)
}

const bloodSugarTab = (item, index) => {
  state.bloodSugarActive = index
}
// 获取昨天 22:00 的日期时间字符串
const getYesterdayAt2200 = () => {
  const yesterday = new Date()
  yesterday.setDate(yesterday.getDate() - 1)
  yesterday.setHours(22, 0, 0, 0)
  return yesterday.toISOString().split('T')[0] + ' 22:00'
}

const timeSleepFun = (date: any, type: string) => {
  // state.tabkeyboardShow = false
  emit('timeSleepFun', date, type)
}

// 血糖-- 根据当前时间匹配时间段标签
const getBloodSugarTime = () => {
  const date = new Date()
  const times = date.getTime()
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  switch (true) {
    case times >= getTimestamp(year, month, day) &&
      times <= getTimestamp(year, month, day, 7, 59, 59):
      state.bloodSugarActive = 0
      break
    case times >= getTimestamp(year, month, day, 8, 0, 0) &&
      times <= getTimestamp(year, month, day, 9, 59, 59):
      state.bloodSugarActive = 1
      break
    case times >= getTimestamp(year, month, day, 10, 0, 0) &&
      times <= getTimestamp(year, month, day, 11, 59, 59):
      state.bloodSugarActive = 2
      break
    case times >= getTimestamp(year, month, day, 12, 0, 0) &&
      times <= getTimestamp(year, month, day, 14, 59, 59):
      state.bloodSugarActive = 3
      break
    case times >= getTimestamp(year, month, day, 15, 0, 0) &&
      times <= getTimestamp(year, month, day, 17, 59, 59):
      state.bloodSugarActive = 4
      break
    case times >= getTimestamp(year, month, day, 18, 0, 0) &&
      times <= getTimestamp(year, month, day, 20, 59, 59):
      state.bloodSugarActive = 5
      break
    case times >= getTimestamp(year, month, day, 21, 0, 0) &&
      times <= getTimestamp(year, month, day, 23, 59, 59):
      state.bloodSugarActive = 6
      break
    default:
      state.bloodSugarActive = 0
      break
  }

  if (state.bloodSugarActive > 4) {
    scrollLeft = '440rpx'
  } else {
    scrollLeft = '0rpx'
  }
}

const getTimestamp = (year: any, month: any, day: any, hour = 0, minute = 0, second = 0) => {
  const date = new Date(year, month - 1, day, hour, minute, second)
  return date.getTime()
}
const timeFun = () => {
  if (state.editType != 'edit') {
    // state.tabkeyboardShow = false
    emit('timeFun', state.time)
  }
}
const measurementFun = () => {
  if (
    props.healthType == 'bmi' ||
    props.healthType == 'sbp' ||
    props.healthType == 'blood_sugar'
  ) {
    emit('measurementFun')
  }
}
const goit = () => {
  emit('onGoit')
}
const selectFile = (files: any) => {
  emit('onSelectFile', files)
}
const deleteFile = (file: any) => {
  props.picInfo.campWieghtPics.splice(file.index, 1)
}
const handleOversize = () => {
  uni.showToast({
    title: '单张图片最大限制为10M，请重新选择',
    icon: 'none'
  })
}
defineExpose({
  add,
  setTime,
  setSleepTime,
  setWakeupTime
})
</script>
<style lang="scss" scoped>
.popup-wrap {
    padding-bottom: calc(160rpx + constant(safe-area-inset-bottom));
    padding-bottom: calc(160rpx + env(safe-area-inset-bottom));

    .title {
      padding: 32rpx;
      font-size: 32rpx;
      font-weight: 700;
      text-align: center;
      border-bottom: 1rpx solid #e5e6eb;
    }

    .popupContent {
      padding: 32rpx;
      font-size: 30rpx;
      color: #222;
    }
    .scroll-slide {
      max-height: 800rpx;
    }

    .tabKey {
      position: relative;
      padding: 20rpx 30rpx 30rpx;

      .name {
        font-size: 30rpx;
        font-weight: 700;
        color: #00d1b6;

        &.on {
          color: #fff;
        }
      }

      .keyboard {
        position: absolute;
        top: 50%;
        right: 30rpx;
        transform: translateY(-50%);

        .img {
          display: inline-block;
          font-size: 36rpx;
          color: #999;
          vertical-align: middle;
          width: 36rpx;
          height: 36rpx;
        }

        .key {
          display: inline-block;
          margin-left: 10rpx;
          font-size: 28rpx;
          color: #222;
          vertical-align: middle;
        }
      }
    }

    .listWraps {
      width: calc(100% - 32rpx);
      height: 118rpx;
      margin: 32rpx 0rpx 0 32rpx;

      .scroll-view_H {
        width: 100%;
        white-space: nowrap;
      }

      .item {
        display: inline-block;
        // display: flex;
        width: 112rpx;
        height: 110rpx;
        margin-right: 16rpx;
        text-align: center;
        background: #fafafa;
        border-radius: 12rpx;

        .name {
          display: block;
          width: 100%;
          margin: 10rpx 0 8rpx;
          font-size: 28rpx;
          font-weight: 600;
          color: #333;
          text-align: center;

        }

        .time-title {
          display: block;
          width: 100%;
          font-size: 26rpx;
          font-weight: 400;
          color: #666;
          text-align: center;
        }

        &.on {
          background: #00d1b6;

          .name {
            color: #fff;
          }

          .time-title {
            color: #fff;
          }

        }
      }
    }

    .btn {
      height: 88rpx;
      margin: 0 32rpx;
      font-size: 32rpx;
      font-weight: 700;
      line-height: 88rpx;
      color: #fff;
      text-align: center;
      background: #00d1b6;
      border-radius: 44rpx;
    }

    .fixedBtn {
      position: fixed;
      bottom: 0;
      left: 0;
      width: 100%;
      padding: 24rpx 0;
      padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
      padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
      color: #fff;
      text-align: center;
      background: #fff;
      border-top: 1rpx solid #e5e6eb;

      .name {
        display: inline-block;
        width: calc(100% - 60rpx);
        padding: 22rpx 0;
        margin: 0 30rpx;
        font-size: 32rpx;
        background: #00d1b6;
        border-radius: 50rpx;
      }
    }

    .measure {
      display: inline-block;
      width: 100%;
      padding-bottom: 30rpx;
      background: #fff;

      .numWrap {
        display: flex;
        flex-flow: row wrap;
        align-items: center;
        justify-content: center;
        // grid-template-columns: repeat(2, 1fr);
        margin: 20rpx 30rpx 0;
        background: #fafafa;
        border-radius: 4rpx;

        .item {
          display: inline-block;
          // width: 33.3%;
          height: 200rpx;
          padding: 10rpx 0 0rpx;
          margin: 0;
          vertical-align: middle;

          .value {
            display: block;
            width: 100%;
            padding: 20rpx 0 8rpx;
            font-size: 48rpx;
            color: #00d1b6;
            text-align: center;
            background: #fafafa;
            border: 0;
          }

          .wraps {
            padding: 10rpx 0;
            margin: 0 20rpx;
            font-size: 30rpx;
            color: #00d1b6;
            text-align: center;
            border-top: 1rpx solid #00d1b6;

            .name {
              display: inline-block;
              vertical-align: middle;

              &:nth-child(1) {
                margin-right: 8rpx;
              }
            }
          }
        }
      }
    }

    .measureTime {
      position: relative;
      display: flex;
      justify-content: space-between;
      padding: 32rpx 0;
      margin: 0 32rpx;

      .name {
        font-size: 30rpx;
        font-weight: 700;
        color: #222;
      }

      .time {
        min-width: 200rpx;
        font-size: 30rpx;
        font-weight: 400;
        color: #222;
        text-align: right;

        .titles {
          display: inline-block;
          vertical-align: middle;
        }

        .img {
          display: inline-block;
          width: 30rpx;
          height: 30rpx;
          vertical-align: middle;
        }
      }
    }

    .upload-title {
      font-size: 30rpx;
      font-weight: 700;
      color: #222;
      margin: 16rpx 32rpx;
      .tips {
        font-size: 24rpx;
        font-weight: 400;
        color: #666;
      }
    }

    .file-box {
      padding: 0 32rpx 24rpx;
      .scroll-upload {
        max-height: 330rpx;
        overflow: auto;
      }
    }

    .sleepTime {
      padding: 32rpx;
      margin-bottom: 24rpx;
      background: #fafafa;
      border: 1rpx solid #e5e6eb;
      border-radius: 16rpx;
    }

    .measureDetail {
      margin: 0 32rpx;
      font-size: 26rpx;
      color: #999;

      .item {
        display: block;

        &:nth-child(2) {
          margin-top: 10rpx;
        }
      }
    }

    .content {
      position: relative;

      .contentWrap {
        margin: 0 32rpx;

        .contentItem {
          margin-top: 32rpx;
          font-size: 32rpx;
          color: #222;
        }

        .img {
          display: block;
          width: 100%;
          height: auto;
          margin-top: 30rpx;
        }
      }

      .fixedBtn {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 24rpx 0;
        padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
        padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
        color: #fff;
        text-align: center;
        background: #fff;
        border-top: 1rpx solid #fff;

        p {
          padding: 22rpx 0;
          margin: 0 30rpx;
          font-size: 32rpx;
          background: #02bcc3;
          border-radius: 50rpx;
        }
      }
    }
}
</style>